import store from "../store";

export function getLabel(dictKey, dictValue) {
    let myMap = new Map();
    myMap = store.getters.sysDict;
    if (!myMap.has(dictKey)) {
        return "未定义";
    }
    let keyMap = new Map();
    keyMap = myMap.get(dictKey);
    if (!keyMap.has(dictValue)) {
        return "未定义";
    }

    return keyMap.get(dictValue);
}

export function getEntries(dictKey) {
    if (!store.getters.sysDict.has(dictKey)) {
        return [];
    }

    let ret = [];
    for (var [value, label] of store.getters.sysDict.get(dictKey)) {
        let rec = {
            value: value,
            label: label
        };
        ret.push(rec);
    }
    return ret;
}

export function hasPermission(url) {
    for (var authorities of store.getters.myuser.authorities) {
        if (authorities.authority === url) {
            return true;
        }
    }
    return false;
}
